Skip to content

feat: support swipe to switch week#17

Open
Kaltsit-cell wants to merge 1 commit intoOpenAHU:masterfrom
Kaltsit-cell:schedule-swipe-week-switch
Open

feat: support swipe to switch week#17
Kaltsit-cell wants to merge 1 commit intoOpenAHU:masterfrom
Kaltsit-cell:schedule-swipe-week-switch

Conversation

@Kaltsit-cell
Copy link

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces horizontal paging to the schedule screen so users can swipe between weeks, and wires the week selector to control the pager.

Changes:

  • Added HorizontalPager/rememberPagerState to enable week-to-week swiping.
  • Updated week selector taps and “locate current week” action to scroll the pager.
  • Added effects to synchronize pager scrolling with the week selector list position.
Comments suppressed due to low confidence (1)

app/src/main/java/com/ahu/ahutong/ui/screen/main/Schedule.kt:257

  • Inside HorizontalPager { … }, the page index parameter isn’t used; all pages render based on the single global currentWeek. This means every page’s content is identical and changes globally when currentWeek changes, which defeats paging and can produce confusing swipe behavior (especially with prefetch/offscreen pages). Derive a weekForPage = page + 1 and use that for weekDates, course filtering, and highlighting, instead of currentWeek inside the pager content.
        HorizontalPager(
            state = pagerState,
            modifier = Modifier.fillMaxWidth()
        ) {
        Box(
            modifier = with(CourseCardSpec) {
                Modifier
                    .fillMaxWidth()
                    .height(mainRowHeight + (cellHeight + cellSpacing) * 13 + 24.dp)
                    .clip(SmoothRoundedCornerShape(32.dp))
                    .background(99.n1 withNight 20.n1)
                    .padding(top = 8.dp)
                    .padding(cellSpacing)
            }
        ) {
            // TODO: current time indicator
            // weekday tags

            val weekDates by remember(currentWeek, scheduleConfig?.startTime) {
                mutableStateOf(
                    List(7) { index ->
                        Calendar.getInstance().apply {
                            time = scheduleConfig?.startTime
                                ?: SimpleDateFormat("MM-dd", Locale.CHINA).parse("09-01")
                            add(Calendar.DATE, ((currentWeek - 1) * 7) + index)
                        }
                    }
                )
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 80 to +106
var currentWeek by rememberSaveable { mutableStateOf(scheduleConfig?.week ?: 1) }
val pagerState = rememberPagerState(
initialPage = (currentWeek - 1).coerceAtLeast(0),
pageCount = { 20 }
)
val state = rememberLazyListState(
initialFirstVisibleItemIndex = (currentWeek - 3).coerceAtLeast(0)
)
val scheduleResult = scheduleViewModel.schedule.observeAsState().value
val schedule = scheduleResult?.getOrNull() ?: emptyList()
val context = LocalContext.current

LaunchedEffect(pagerState.isScrollInProgress) {
if (!pagerState.isScrollInProgress) {
state.animateScrollToItem(
(currentWeek - 3).coerceAtLeast(0)
)
}
}

LaunchedEffect(scheduleConfig?.week) {
scheduleConfig?.week?.let { currentWeek = it }
}


LaunchedEffect(pagerState.currentPage) {
currentWeek = pagerState.currentPage + 1
}
Comment on lines 201 to +205
scope.launch {
state.animateScrollToItem((currentWeek - 3).coerceAtLeast(0))
}
scope.launch {
pagerState.animateScrollToPage((scheduleConfig?.week ?: 1) - 1)
@@ -120,7 +138,6 @@ fun Schedule(scheduleViewModel: ScheduleViewModel = hiltViewModel()) {
) {
Row(
modifier = Modifier.padding(end = 8.dp),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants